import { AccessLevel, SingletonProto } from "@eggjs/tegg";


@SingletonProto({
    accessLevel: AccessLevel.PUBLIC
})
export class DateUtils {

    /**
     * 返回星期几
     * @param time 日期
     * @returns 
     */
    static weekDay(time: string) {
        const weekNum = new Date(time).getDay();
        const week = {
            0: '星期天',
            1: '星期一',
            2: '星期二',
            3: '星期三',
            4: '星期四',
            5: '星期五',
            6: '星期六'
        } as any
        return week[weekNum] ? week[weekNum] : '日期错误';
    }

    /**
     * 格式化对应日期
     * @param date 日期
     * @returns yyyy-mm-dd
     */
    static getComDate(date: string) {
        const TheDate = new Date(date);
        return TheDate.getFullYear() + '-' + (TheDate.getMonth() + 1).toString().padStart(2, '0') + '-' + TheDate.getDate().toString().padStart(2, '0');
    }

    /**
     * 获取今天格式化日期
     * @returns yyyy-mm-dd
     */
    static getNowComDate() {
        const TheDate = new Date();
        return TheDate.getFullYear() + '-' + (TheDate.getMonth() + 1).toString().padStart(2, '0') + '-' + TheDate.getDate().toString().padStart(2, '0');
    }

    /**
     * 获取今天格式化日期
     * @returns yyyy-mm-dd
     */
    static getNowZnDate() {
        const TheDate = new Date();
        let dayType = '白班';
        if (TheDate.getHours() == 12 || TheDate.getHours() == 20) {
            dayType = '白班'
        } else if (TheDate.getHours() == 8) {
            TheDate.setDate(TheDate.getDate() - 1);
            dayType = '夜班'
        }
        let year = TheDate.getFullYear() + '年';
        let month = (TheDate.getMonth() + 1).toString().padStart(2, '0') + '月';
        let day = TheDate.getDate().toString().padStart(2, '0') + '日';
        return year + month + day + dayType;
    }

    /**
     * 获取今天格式化日期
     * @returns yyyy-mm-dd
     */
    static getNowFullDateJSON() {
        const TheDate = new Date();
        return TheDate.getFullYear() + '-' + (TheDate.getMonth() + 1).toString().padStart(2, '0') + '-' + TheDate.getDate().toString().padStart(2, '0') + ' ' + TheDate.getHours().toString().padStart(2, '0') + '时' + TheDate.getMinutes().toString().padStart(2, '0') + '分' + TheDate.getSeconds().toString().padStart(2, '0') + '秒 ' + TheDate.getMilliseconds() + '毫秒';
    }

    /**
     * 获取今天格式化日期
     * @returns yyyy-mm-dd
     */
    static getNowFullDate() {
        const TheDate = new Date();
        return TheDate.getFullYear() + '-' + (TheDate.getMonth() + 1).toString().padStart(2, '0') + '-' + TheDate.getDate().toString().padStart(2, '0') + ' ' + TheDate.getHours().toString().padStart(2, '0') + ':' + TheDate.getMinutes().toString().padStart(2, '0') + ':' + TheDate.getSeconds().toString().padStart(2, '0') + ' ' + TheDate.getMilliseconds();
    }
}